package com.mine.androidlearn.api;

import android.content.Context;

import com.mine.androidlearn.api.bean.WeatherInfoBean;

import rx.Observable;


/**
 *
 * @author: hujianghao5
 * @version: V1.0 2018/8/3 20:38
 */
public class ApiWrapper extends RetrofitUtil {

    private static ApiWrapper instance;
    private final IApiService mApiService;
    private final Context mContext;
//    private final IApiService mApiProxy; //后期添加   // TODO: 2018/8/3 question

    public ApiWrapper(Context context) {
        super(context);
        mContext = context;
        mApiService = getService(IApiService.class);
//        mApiProxy = getProxy(IApiService.class);
    }

    /**
     * 单例模式
     * @param context
     * @return
     */
    public static synchronized ApiWrapper getInstance(Context context) {
        if (instance == null) {
            instance = new ApiWrapper(context.getApplicationContext());
        }
        return instance;
    }


    /**
     * 获取天气
     * @param key 天气网站要求的对应key
     * @param city 城市
     * @return
     */
    public Observable<WeatherInfoBean> loadWeatherInfo(final String key, final String city) {
        return mApiService.loadWeatherInfo(key, city)
                .compose(this.<WeatherInfoBean>applySchedulers2());
    }


    /**
     * 登录
     *
     * @param deviceType 设备类型 1-iOS 2-Android
     * @param deviceId   设备ID iOS-UDID Android-IMEI
     * @param deviceName 设备名称
     * @return
     */
    public Observable<Void> registerMobileDevice(final Integer deviceType, final String deviceId,
                                                 final String deviceName) {
        return mApiService.registerMobileDevice(deviceType, deviceId, deviceName)
                .compose(this.<Void>applySchedulers());
    }

}
